package org.jetlinks.demo.protocol.siterwell.tcp.message;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.jetlinks.demo.protocol.siterwell.tcp.util.ByteUtils;

/**
 * 登录请求命令
 * 网关发往平台的命令数据
 */
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class D2SAuthRequest extends AbstractCommandRequest {

    private int heartInterval;  // 单位分钟
    private String iccid;      // sim卡iccid号
    private String tel1;       // 手机号1
    private String tel2;       // 手机号2

    public static D2SAuthRequest of(byte[] data) {
        D2SAuthRequest message = new D2SAuthRequest();
        message.fromBytes(data, 0);
        return message;
    }


    @Override
    protected void parseData() {
        String hexDataSource = this.getHexDataSource();
        String hexHeartInterval = ByteUtils.subHexStrByByte(hexDataSource, 0, 1);
        this.heartInterval = Integer.parseInt(hexHeartInterval);
        this.iccid = ByteUtils.subHexStrByByte(hexDataSource, 1, 21);
        this.tel1 = ByteUtils.subHexStrByByte(hexDataSource, 21, 27);
        this.tel2 = ByteUtils.subHexStrByByte(hexDataSource, 27, 33);
    }


    @Override
    public String toString() {
        return "{" +
                "iccid=" + iccid +
                ", heartInterval=" + heartInterval +
                ", tel1=" + tel1 +
                ", tel2=" + tel2 +
                '}';
    }
}
